package com.sys.gradepaysys.service;

import com.sys.gradepaysys.dao.BaseDao;
import com.sys.gradepaysys.entity.Clazz;
import com.sys.gradepaysys.entity.Grade;
import com.sys.gradepaysys.entity.Student;

import java.util.List;

public class StudentServiceImpl implements StudentService{
    @Override
    public Student login(String username, String password) {
        String sql="select * from student where s_num=?";
        String arr[]={username};
        List<Student> students = BaseDao.selectStuList(sql, arr);
        Student student=new Student();
        if (students.size()==1){
            for (Student student1 : students) {
                student=student1;
            }
            if (!student.getPassword().equals(password)){
                throw new RuntimeException("密码不正确!");
            }
        }else {
            throw new RuntimeException("该学号不存在!");
        }
        return student;
    }

    @Override
    public List<Grade> getAllGrade() {
        return BaseDao.selectGradeList();
    }

    @Override
    public List<Clazz> getAllClazz() {
        return BaseDao.selectClazzList();
    }

    @Override
    public boolean registerStu(Student student) {
        String sql="INSERT INTO student (s_name, s_num, password, sex,age, qq, s_tel, g_name, c_name) VALUES (?, ?, ?, ?, 18, ?, ?, ?, ?)";
        String arr[]={student.getsName(),student.getsNum(),student.getPassword(),student.getSex(),student.getQq(),student.getsTel(),student.getgName(),student.getCname()};
        boolean b = BaseDao.DoObject(sql, arr);
        return b;
    }
}
